#include <cstddef>
#include <cstdint>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>

namespace xncc {
namespace shared {

    enum class SHM_MODE : uint8_t
    {
        READ_ONLY    = O_RDONLY,
        READ_WRITE   = O_RDWR,
        INVALID_MODE = 0xff
    };

    enum class SHM_FILE_MODE : uint8_t
    {
        CREATE,
        OPEN,
        OPENORCREATE
    };
    class MmapSHMObject
    {
      public:
        MmapSHMObject(SHM_FILE_MODE, SHM_MODE mode, const char* name, long long fileSize, unsigned int perm = 0644);

        ~MmapSHMObject();

        static bool remove(const char* name);

        void* getAddress() { return base_; }

      private:
        int         shmHandle_;
        void*       base_;
        std::size_t size_;
    };
}  // namespace shared
}  // namespace xncc
